Imports System.ComponentModel

<Serializable()> _
Public Class Section2
    Inherits BaseDescriptor

    '0.9.5
    'Private MAX_VALUE As Double = 999
    'Private MIN_VALUE As Double = -999

    'S2C
    Private _VDARK As Double() = {}
    Private _VLIGHT As Double() = {}
    Private _VSR As Double() = {}
    Private _NOUTFILE As Integer

    <CustomOrder(1), CustomCategory("S2C1"), CustomDisplayName("NDARK"), CustomDescription("NDARK"), DefaultValue(0), RefreshProperties(RefreshProperties.All)> _
    Public Property NDARK() As Integer
        Get
            Return _VDARK.Length
        End Get
        Set(ByVal value As Integer)
            Array.Resize(_VDARK, value)
        End Set
    End Property

    <CustomOrder(2), CustomCategory("S2C1"), CustomDisplayName("VDARK"), CustomDescription("VDARK"), TypeConverter(GetType(CustomArrayConverter))> _
    Public ReadOnly Property VDARK() As Double()
        Get
            Return _VDARK
        End Get
    End Property

    <CustomOrder(3), CustomCategory("S2C1"), CustomDisplayName("NLIGHT"), CustomDescription("NLIGHT"), DefaultValue(0), RefreshProperties(RefreshProperties.All)> _
    Public Property NLIGHT() As Integer
        Get
            Return _VLIGHT.Length
        End Get
        Set(ByVal value As Integer)
            Array.Resize(_VLIGHT, value)
        End Set
    End Property

    <CustomOrder(4), CustomCategory("S2C1"), CustomDisplayName("VLIGHT"), CustomDescription("VLIGHT"), TypeConverter(GetType(CustomArrayConverter))> _
    Public ReadOnly Property VLIGHT() As Double()
        Get
            Return _VLIGHT
        End Get
    End Property

    <CustomOrder(5), CustomCategory("S2C1"), CustomDisplayName("NSR"), CustomDescription("NSR"), DefaultValue(0), RefreshProperties(RefreshProperties.All)> _
    Public Property NSR() As Integer
        Get
            Return _VSR.Length
        End Get
        Set(ByVal value As Integer)
            Array.Resize(_VSR, value)
        End Set
    End Property

    <CustomOrder(6), CustomCategory("S2C1"), CustomDisplayName("VSR"), CustomDescription("VSR"), TypeConverter(GetType(CustomArrayConverter))> _
    Public ReadOnly Property VSR() As Double()
        Get
            Return _VSR
        End Get
    End Property

    <CustomOrder(7), CustomCategory("S2C2"), CustomDisplayName("NOUTFILE"), CustomDescription("NOUTFILE"), DefaultValue(0), TypeConverter(GetType(CustomInt32ConverterNOUTFILE))> _
    Public Property NOUTFILE() As Object
        Get
            Return _NOUTFILE
        End Get
        Set(ByVal value As Object)
            _NOUTFILE = CInt((New CustomInt32ConverterNOUTFILE).ConvertFrom(value))
        End Set
    End Property

    '0.9.5
    'Public Sub SortValues()
    '    _VDARK = Me.Sort(_VDARK)
    '    _VLIGHT = Me.Sort(_VLIGHT)
    '    _VSR = Me.Sort(_VSR)
    'End Sub
    Public Sub SortValues(ByVal MinValue As Double, ByVal MaxValue As Double)
        _VDARK = Me.Sort(MinValue, MaxValue, _VDARK)
        _VLIGHT = Me.Sort(MinValue, MaxValue, _VLIGHT)
        _VSR = Me.Sort(MinValue, MaxValue, _VSR)
    End Sub


    Private Function Sort(ByVal MinValue As Double, ByVal MaxValue As Double, ByVal values As Double()) As Double()
        Dim ValueList As New List(Of Double)

        For Each dblValue As Double In values
            '0.9.5
            If dblValue < MinValue OrElse dblValue > MaxValue Then Continue For

            If dblValue >= 10 OrElse dblValue <= -10 Then
                '0.9.5
                'dblValue = Math.Round(dblValue, 0)
                dblValue = Math.Round(dblValue, 1)
            Else
                '0.9.5
                'dblValue = Math.Round(dblValue, 1)
                dblValue = Math.Round(dblValue, 2)
            End If
            '0.9.5
            'If dblValue > MAX_VALUE Then
            '    dblValue = MAX_VALUE
            'ElseIf dblValue < MIN_VALUE Then
            '    dblValue = MIN_VALUE
            'End If
            If Not ValueList.Contains(dblValue) Then
                ValueList.Add(dblValue)
            End If
        Next
        ValueList.Sort()
        '0.9.5
        'ValueList.Reverse()

        Return ValueList.ToArray()
    End Function

End Class
